<!DOCTYPE html>
<html  xmlns="http://www.w3.org/1999/xhtml"
       xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="featon inc.">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vendor/skin/ftskin.css">
    <title></title>
</head>

<body style="margin-bottom: 60px;">

<div class="ft-subpage-wrapper container-fluid">
    <form id="form1" name="form1" action="#" method="post">
        <div class="row">
            <div class="col-lg-12" id="form_table">
                <fieldset>
                    <legend id="titleText" style="font-weight: bold">--</legend>
                    <table id="" class="form-table form-table-border" cellpadding="0" cellspacing="0" >
                        <tr>
                            <th><span class="f_red">*</span>部门全称</th>
                            <td colspan="3">
                                <input id="dept_name" name="dept_name" type="text" class="form-control" value="" placeholder="">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="f_red">*</span>部门简称</th>
                            <td colspan="3">
                                <input id="dept_sortname" name="dept_sortname" type="text" class="form-control" value="" placeholder="">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th>所属业务行政区划</th>
                            <td>
                                <div class="input-group">
                                    <input id="dq_yw_id" name="dq_yw_id" type="hidden" value="0">
                                    <input id="dq_yw_name" name="dq_yw_name" type="text" class="form-control" value="" readOnly="readOnly" >
                                    <span class="input-group-btn  ft-input-group-btn">
                                <button class="btn btn-default" type="button" onclick="openSelectSinglDiQuPage('选择地区','setDiQuID')"> 选择地区</button>
                              </span>
                                </div>
                            </td>
                            <th>部门类型</th>
                            <td>
                                <select id="dept_type" name="dept_type" class="form-control">
                                    <option value="0">一般部门</option>
                                    <option value="1">免疫部门</option>
                                    <option value="2">检疫部门</option>
                                    <option value="3">屠宰场部门</option>
                                    <option value="4">诊疗机构</option>
                                    <option value="9">检疫免疫部门</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th>部门编号</th>
                            <td>
                                <input id="dept_code" name="dept_code" type="text" class="form-control" value="" placeholder="">
                                <span class="cError"></span>
                            </td>
                            <th>联系电话</th>
                            <td>
                                <input id="phone" name="phone" type="text" class="form-control" value="" placeholder="">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th>详细地址</th>
                            <td colspan="3">
                                <input id="address" name="address" type="text" class="form-control" value="" placeholder="">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th>经/纬度</th>
                            <td  colspan="3">
                                <div class="input-group">
                                    <input id="longitude" name="longitude" type="text" class="form-control" value="" placeholder="" style="width:200px">
                                    <input id="latitude" name="latitude" type="text" class="form-control" value="" placeholder="" style="width:200px">
                                    <span class="input-group-btn ft-input-group-btn">
                                  <button class="btn btn-info" type="button" onclick="openMapPosition()"><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span> 获取点坐标</button>
                              </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>备注</th>
                            <td colspan="3">
                                <textarea id="remark" name="remark" class="form-control" rows="3" ></textarea>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <div class="bottom-tools-box">
                    <button type="button" class="btn btn-info"  id="save_but"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> 保存</button>
                    <button type="button" class="btn btn-warning" onclick="top.tab_colseOnclick();"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span> 取消</button>
                </div>

            </div>
        </div>
    </form>
</div>

<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/validate/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>

<script>
    var parentID = [[${parentID}]];
    var dept_id = [[${dept_id}]];

    jQuery(function($) {
        iniInfoForm();
        if(dept_id != "" && dept_id != null)
        {
            $("#titleText").text("修改部门信息");
            defaultBean = top.ajax.syncl("/dept/getDeptBean/"+dept_id,"");
            if(defaultBean)
            {
                $("#form_table").autoFill(defaultBean);
                $('#save_but').click(UpdateObject)
            }

        }else {
            $("#titleText").text("添加部门信息");
            $('#save_but').click(addObject)
        }
    });

    $(document).ready(function(){

    });

    function iniInfoForm()
    {
        var validator = $("#form1").validate({
            debug:true,
            rules: {
                dept_sortname: {
                    required: true
                },
                dept_name: {
                    required: true
                }
            },
            messages: {
                dept_sortname: {
                    required: "部门简称不能为空！"
                },
                dept_name: {
                    required: "部门全称不能为空！"
                }
            },
            errorPlacement: function(error, element) {
                error.appendTo( element.parents('td').find(".cError") );
                // error.appendTo(element.parent());
            },
            submitHandler: function(form) {

            }
        });
    }

    var is_submit = false;
    function addObject()
    {
        if($("#form1").valid())
        {
            if(is_submit == false)
            {
                is_submit = true;
                var bean = top.ajax.getBean("com.yixun.entity.YxDept");
                $("#form_table").autoBind(bean);
                bean.parent_id = parentID;
                if(top.ajax.synclBody("/dept/add",bean))
                {
                    modelWindow.alert(top.CMSLang.Add_success);
                    top.getCurrentFrameObj().insertTreeNode(bean.dept_id,bean.dept_name);
                    top.getCurrentFrameObj().loadListble();
                    top.tab_colseOnclick();
                }else
                {
                    modelWindow.error(top.CMSLang.Add_fail);
                    is_submit = false;
                }
            }
        }
    }

    function UpdateObject()
    {
        if($("#form1").valid())
        {
            if(is_submit == false)
            {
                is_submit = true;
                var bean = top.ajax.getBean("com.yixun.entity.YxDept");
                $("#form_table").autoBind(bean);
                bean.dept_id = dept_id;
                if(top.ajax.synclBody("/dept/edit",bean))
                {
                    modelWindow.alert(top.CMSLang.Add_success);
                    top.getCurrentFrameObj().updateTreeNode(bean.dept_id,bean.dept_name);
                    top.getCurrentFrameObj().loadListble();
                    top.tab_colseOnclick();
                }else
                {
                    modelWindow.error(top.CMSLang.Add_fail);
                    is_submit = false;
                }
            }
        }
    }

    function openSelectSinglDiQuPage(title,handl_name)
    {
        modelWindow.openFrameWindow(title,"/ywdiqu/go_select_single_ywdiqu?handle_name="+handl_name+'&frame_name='+modelWindow.getFrameWindow(),450,410);
    }

    function setDiQuID(id,name)
    {
        $('#dq_yw_id').val(id);
        $('#dq_yw_name').val(name);
    }

    /*************************地图选择  开始***********************************/
    function openMapPosition()
    {
        var position = '';
        var longitude = $('#longitude').val();
        var latitude = $('#latitude').val();
        if(longitude != '')
        {
            position = longitude+','+latitude;
        }
        modelWindow.openFrameWindow("拾取坐标","/static/vendor/map/ol-tdt/get-point.html?position="+position,900,750);
    }

    function setPoint(position)
    {
        if(position == '')
        {
            $('#longitude').val('');
            $('#latitude').val('');
        }else{
            var tempA = position.split(',');
            $('#longitude').val(tempA[0]);
            $('#latitude').val(tempA[1]);
        }
    }
    /*************************地图选择  结束***********************************/
</script>
</body>

</html>
